/*
day147
2020.1.22
*/
#include<string>
#include<iostream>
#include<unordered_map>
using namespace std;


class Solution1 
{
public:
    int numJewelsInStones(string J, string S) 
	{
		int res=0;
        unordered_map<char,int> m;
        for(int i=0;i<J.size();i++)
        {
        	m[J[i]]=1;
		}
		
		for(int i=0;i<S.size();i++)
		{
			char tem=S[i];
			if(m[tem])	++res;
		}
		
		return res;
    }
};


class Solution2 {
public:
    int numJewelsInStones(string J, string S) 
	{
		int res=0;
        int arr[52];
        for(int i=0;i<J.size();i++)
        {
        	char tem=J[i];
        	if(tem<='Z') ++arr[tem-'A'];
        	else	++arr[tem-'a'+26];
		}
		
		for(int i=0;i<S.size();i++)
		{
			char tem=S[i];
			if(tem<='Z')
			{
				if(arr[tem-'A']) ++res;
			}
			
        	else if(arr[tem-'a'+26])	++res;
		}
		
		return res;
    }
};


int main()
{
	Solution2 s;
	string J = "z", S = "ZZ";
	cout<<s.numJewelsInStones(J,S)<<endl;
	return 0;
}
